﻿using System.Text;
using TweetSayingsLibrary.App.DataDoc;
using Dimebrain.TweetSharp.Fluent;
using System.Collections.Generic;
using System;
using TweetSayingsLibrary.Data.Access;

namespace TweetSayingsLibrary.App.Entity
{
    public class Me
    {
        public static IDataDoc Followers()
        {
			return Current.SessionTrack.ApiCaller.Request(t => t.Users().GetFollowers().CreateCursor(), true); 
        }

        public static IDataDoc Following()
        {   
            return Current.SessionTrack.ApiCaller.Request(t => t.Users().GetFriends().CreateCursor(), true); 
        }

        public static IDataDoc Following(long cursor)
        {
            return Current.SessionTrack.ApiCaller.Request(t => t.Users().GetFriends().GetCursor(cursor).CreateCursor(), true);
        }

        public static IDataDoc FriendsNotFollowing(int page, int take)
        {
			if (page < 1)
				page = 1;
			
			if (take < 1)
				take = 1;

            //using (TableStore<Friend> friends = TableStore<Friend>.Open(Current.Visitor.Id))
            //using (TableStore<Follower> followers = TableStore<Follower>.Open(Current.Visitor.Id))
            //{
            //    List<Friend> celebs = friends.ReadAllExcluding(followers);
            //    return new DataDocList(new List<DataDocValue>()
            //                            {
            //                                new DataDocValue("users", SyntheticUserList(celebs.Skip((page - 1)*take).Take(take)))
            //                            });
            //}

            return null;
        }

		public static IDataDoc FollowingNotFriends(int page, int take)
		{
			if (page < 1)
				page = 1;

			if (take < 1)
				take = 1;

            //using (TableStore<Friend> friends = TableStore<Friend>.Open(Current.Visitor.Id))
            //using (TableStore<Follower> followers = TableStore<Follower>.Open(Current.Visitor.Id))
            //{
            //    List<Follower> boring = followers.ReadAllExcluding(friends);
            //    return new DataDocList(new List<DataDocValue>()
            //                            {
            //                                new DataDocValue("users", SyntheticUserList(boring.Skip((page - 1)*take).Take(take)))
            //                            });
            //}
            return null;
		}
        
        public static IDataDoc FollowingLists()
        {
            return Current.SessionTrack.ApiCaller.Request(t => t.Lists().GetSubscriptions(App.Current.Visitor.Screen_Name.ToLower()), false);
        }

        public static IDataDoc Mentions()
        {
            return Mentions(1, 20);
        }

        public static IDataDoc Mentions(int page, int take)
        {
            return Current.SessionTrack.ApiCaller.Request(t => t.Statuses().Mentions().Skip(page).Take(take), true);
        }

        public static IDataDoc Details()
        {
            return App.Current.Visitor.Details;
        }

		public static IDataDoc AliasList()
		{
            //List<Visitor> alias = Current.Visitor.Alias;

            //List<DataDocValue> list = new List<DataDocValue>();

            //using (TableStore<TwitterUserDetails> details = TableStore<TwitterUserDetails>.Open())
            //{
            //    int i = 0;
            //    foreach (Visitor account in alias)
            //    {
            //        TwitterUserDetails detial = details.Find(account.Id);
            //        if (detial == null)
            //            continue;

            //        list.Add(new DataDocValue(i.ToString(), new List<DataDocValue>
            //                                                    {
            //                                                        new DataDocValue("twitter_id", account.Id),
            //                                                        new DataDocValue("screen_name", account.ScreenName),
            //                                                        new DataDocValue("profile_image_url", detial.ProfileImageUrl),
            //                                                        new DataDocValue("_primary", account.IsPrimaryIdentity)
            //                                                    }));
            //        i++;
            //    }
            //}

            //return new DataDocList(new List<DataDocValue>() { new DataDocValue("", list), new DataDocValue("count", alias.Count() + 1) });
            return null;
		}

        private static IDataDoc SingleStatus(string status)
        {
            return new DataDocList(new List<DataDocValue> { new DataDocValue("status", status) });
        }
    }
}